hiendich = {};
hiendich.tickerwidth = '320';
hiendich.tickerheight = '100';
hiendich.tickerpadding = 5;
hiendich.borderwidth = 1;
hiendich.fnt = "Verdana";
hiendich.fntsize = 10;
hiendich.fntsizelastletter = 10;
hiendich.fntcolor = "880000";
hiendich.fntcolorlastletter = "880000";
hiendich.fntweight = 3;
hiendich.backgroundcolor = "EAFFEE";
hiendich.standstill = 2000;
hiendich.speed = 0;
hiendich.xdistance = 10;
hiendich.ydistance = 20;
hiendich.timer = 0;
hiendich.topposition = 0;
hiendich.leftposition = 0;
hiendich.x = 20;
hiendich.y = 20;
hiendich.i_substring = 0;
hiendich.i_presubstring = 0;
hiendich.i_message = 0;
hiendich.message = "";
hiendich.messagepresubstring = "";
hiendich.messageaftersubstring = "";
hiendich.fntweight = hiendich.fntweight * 100;
hiendich.old_bgColor = "white";
hiendich.new_bgColor = "yellow";
var play_audio_times = 1200;
        
        
        
        
        
        
        
        
        
        
        
function checkVipTrans(){
    Lvip = 0;
    flag = true;
    if(typeof bV != 'undefined'){
        Lvip  = $.base64.decode((bV));
    }
    Mvip  = $.base64.decode((uV));
    if(Lvip==1 & Mvip == 0){
        flag = false;
    }
    return flag;
}
function checkVipaudioLink(link){
    Lvip = 0;
    if(typeof bV != 'undefined'){
        Lvip  = $.base64.decode((bV));
    }
    Mvip  = $.base64.decode((uV) ? uV : 0);
    
    if(Lvip==0){
        return link;
    }
    if(Lvip == 1 & Mvip == 1){
        return link;
    }
    if(Lvip==1 & Mvip == 0){
        return '/06.WWW/uploads/error.mp3';
    }
}
function stopAudio() {
    //var audio_div = document.getElementById("playaudio");
    audio_div = $("#playaudio");
    audio_div.fadeOut();
}        
function playAudio(target,audiolink, notDisplay) {
    audiolink = checkVipaudioLink(audiolink);
    var x = target.offset().left + 50;
    var y = target.offset().top;
    var audio_div = document.getElementById("playaudio");
    if ((navigator.appName == "Netscape") || (navigator.appVersion.indexOf("MSIE 9.0") > 1) || (navigator.appName == "Opera")) {
        x = x + "px";
        y = y + "px"
    }
    if (typeof(notDisplay) == 'undefined') {
        audio_div.style.left = x;
        audio_div.style.top = y
    }
    var id_playaudio = "mp3player" + play_audio_times;
    audio_div.innerHTML = '<div style="width: 185px; height: 20px; background-color: #FFF;cursor:move" > <span title="Close" onclick="stopAudio();" class="icon-off" style="cursor:pointer;margin-left:5px;margin-right:5px"></span><span>english456.vn</span></div>';
    audio_div.innerHTML += "<div id='" + id_playaudio + "'><center>Audio</center></div>";
    audio_div.style.visibility = "visible";
    $("#playaudio").fadeIn();
    jwplayer(id_playaudio).setup({
        'flashplayer': base_url+'/themes/default/assets/js/jwplayer/player.swf',
        'file': audiolink,
        'autostart': 'true',
        'controlbar': 'bottom',
        'skin': base_url+'/themes/default/assets/js/jwplayer/nikitaskin.zip',
        'width': '185',
        'height': '24'
    })
    $(document).keyup(function(){
        if(event.keyCode == 27){
            stopAudio();
        }    
    })
}


function init_question(){
    $("span.answer").click(function(){
        id = $(this).attr("alt");
        $(".hidden_reply").each(function(){
            if($(this).attr("alt") != id){
                $(this).slideUp();
            }
        })
        target = $(this).next();
        $(target).slideToggle();  
    })
    return false;
}















Cufon.replace('.header-at h2,.title_big,.title_small, .cufon,.sub-nav-header-left,.box-tapt-title, .tate,#sub-nav #title', {
    fontFamily: 'League Gothic'
});
Cufon.replace('.cufon2', {
    fontFamily: 'Segoe UI Semibold', 
    textShadow: '1px 1px #ccc',
    hover:{
        color:'orange'
    }
});
Cufon.replace('.cufon2s', {
    fontFamily: 'Segoe UI Semibold'
});
var  DIC = new Array();
function remove_title(){
    i=0;
    $("div.stranslate_div a,a.tip").each(function(){  
        tam_tit = $(this).attr("title");
        DIC[i] = tam_tit;
        $(this).attr('title','');
        $(this).unbind("hover");
        i++;
    })
}










//hide loading bar
function hideLoader1(){
//$('.list_pagin_video').fadeOut(200);
    
}	
$(".pagin_home_n1 li a").click(function(){
    //show the loading bar
    url = $(this).attr("href");
    page_num = $(this).attr("rel");
    x = $(this).parent().parent().parent().parent().prev().find("ul");
    x.css("opacity",0);
    s_parent = x.parent().parent().parent().parent();
    load_obj = s_parent.find("img.ax_load");
    load_obj.fadeIn();
    num = ($(this).attr("name")) ? 0 : $(this).attr("name");
    $.ajax({
        url:url+"/page/"+page_num,
        type:'post',
        success:function(html){
            x.html(html);
            load_obj.hide();
            x.css("opacity",1);
        }            
    })	
    return false;
});
	
// by default first time this will execute
function tab(control,source){
    $(control+' a').click(function(){
        id = $(this).attr("href");
        if($(source+" div#"+id).css("display")=='none'){
            $(source+' div._tab').hide();
            $(source+" div#"+id).fadeIn();
            $(this).parent().parent().find("li").each(function(){
                $(this).removeClass("active");
            })
            $(this).parent().addClass('active');
        }
        return false;
    }); 
}
$().ready(function(){
    $(".fancybox_ajax").attr("href","#login_form_fc");
    $("#playaudio").draggable();
    $(".vlum").each(function(){
        tit = $(this).attr("title");
        if(tit!=''){
            $(this).attr("title","");
            $(this).attr("alt",tit);
        }
    })
    $(".vlum").click(function(e){
        playAudio($(this),$(this).attr("alt"));
    })
    init_question();
    $(".btn_ajax_submit").click(function(){
        id = $(this).attr("alt");
        formx = $(".form_ajax_"+id);
        $.ajax({
            type:'POST',
            data:formx.serialize(),
            url:base_url+"/thanh-vien/ajaxquestion/",
            beforeSend:function(){
            },
            success:function(response){
                data = $.parseJSON(response);
                if(data.status == 1){  
                    if(data.vip == 1){
                        obj = formx.parent().prev();
                        current = parseInt(obj.attr("name"));
                        formx.prev().find("ul").append(data.content);
                        obj.attr("name",(current+1));
                        obj.html("Trả lời ("+(current+1)+")");
                    }
                    formx.find("button.close_cmt").click();
                    formx.find("textarea").val('');
                    return false;
                }
            }
        })
        return false;
    })
    $(".get_question a").click(function(){
        flag = 1;
        if($(this).hasClass("get_old_question")){
            flag = 0;
        }
        off = $(this).attr("alt");
        $.ajax({
            type:'post',
            data:"offset="+off,
            url:base_url+'/mquestion/processquestion/',
            success:function(html){
                $("ul.list_question_").html(html);
                init_question();
            }
        })
    })
    
    
    
    $(".close_cmt").click(function(){
        $(this).parent().parent().slideUp();
        return false;
    })
    
    $("input.search_query_input").css({
        "padding":"4px"
    });
    $(".danhngon_block,a.tip").ChillTip().hover(function(){
        $(this).css({
            "background":"#FCD116"
        });
    },function(){
        $(this).css("background","none");
    });
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    $("a").each(function(){
        if($(this).attr("href")=='#' | $(this).attr("href")==''){
            $(this).addClass("highslide");
            
            
            
        }
    })
    
    
    
    tab('ul.music_block_tab_control','.music_block_tab');
    tab('ul.block_listen_news_comment','.block-info-body');
    tab('ul#ul-study','.video_show_case');
    tab('ul.list_video_trailer','.list_video_trailer_component');    
    tab('ul.control_member','.top_member_list');    
    $(".stranslate_div,.scroll_over").mCustomScrollbar({
        scrollInertia:0
    });
    remove_title();
    $(".enab_tip").click(function(){
        if($(this).text()=='Tắt lời dịch'){
            $(this).text("Bật lời dịch");
            $("div.stranslate_div a,a.tip").unbind("hover");
            remove_title();
        }else{
            j=0;
            $("div.stranslate_div a,a.tip").each(function(){
                $(this).attr('title',DIC[j])
                j++;
            })
            $(this).text("Tắt lời dịch");
            if(checkVipTrans() == true){
                $("div.stranslate_div a,a.tip").ChillTip().hover(function(){
                    $(this).css("background","#FCD116");
                },function(){
                    $(this).css("background","none");
                });
            } else {
                $("div.stranslate_div a,a.tip").ChillTip().hover(function(){
                    $(this).css("background","#FCD116");
                },function(){
                    $(this).css("background","none");
                });
                $("div.stranslate_div a,a.tip").each(function(){
                    $(this).attr("title",'Bạn phải là thành viên VIP mới xem được lời dịch này');
                })
            }
        }
    }) 
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    $('.login_btn').click(function(){
        $("#myModal").bind("show", function() {    // wire up the OK button to dismiss the modal when shown
            $("#myModal a.primary").on("click", function(e) {
                $("#myModal").modal('hide');     // dismiss the dialog
            });
        });


        $("#myModal").modal({                    // finally, wire up the actual modal functionality and show the dialog
            "backdrop"  : "static",
            "keyboard"  : true,
            "show"      : true                     // ensure the modal is shown immediately
        });
        return false;
    })
    
    $(".emoticon_small a").click(function(){
        var nd = $(this).attr("href");
        var curr = $("#display_text").val();
        $("#display_text").val(curr + nd);
        return false;
    })
    $("#class").mCustomScrollbar({
        scrollButtons:{
            enable:true
        },
        scrollInertia:900,
        scrollEasing:"easeOutQuint"
    });
                        
    $(".box-ul-body").mCustomScrollbar({
        scrollButtons:{
            scrollSpeed: 10
        }
    });
                        
    $(".sty-idoms").mCustomScrollbar({
        scrollButtons:{
            enable:true
        },
        scrollInertia:900,
        scrollEasing:"easeOutQuint"
    });
   
    
    $(".mem-body").mCustomScrollbar({
        scrollButtons:{
            enable:true
        },
        scrollInertia:900,
        scrollEasing:"easeOutQuint"
    });
    $(".fancybox_ajax").fancybox({
        'padding':10,
              
        'autoSize':true,
        'transitionIn': 'elastic',
        'transitionOut': 'elastic',
        'width'        : 430,
        helpers : {
            overlay : {
                css : {
                    'background' : 'rgba(0, 0, 0, 0.3)'
                }
            }
        },
        afterClose: function(){
            $("#login_form_fancy .hidden_error").hide();
        }
            
                
    });
    $("#login_form_fancy").submit(function(e){
        $("#login_form_fancy .hidden_error").fadeOut();
        old = $(".form-2-x-y").html();
        $.ajax({
            url:base_url+'/member/login',
            data:$(this).serialize(),
            type: 'post',
            beforeSend:function(){
                $(".loading_animate").show();
                $(".form-2-x-y").html("<h4><center><font color='#0183AD' size='17px'>Processting!<br><img src='"+base_url+"/themes/default/assets/img/325.gif'></font></center></h4>");
            },
            success:function(data){
                js = $.parseJSON(data);
                $(".form-2-x-y").html(old);
                if(js.stt==false){
                    $("#login_form_fancy .hidden_error").fadeIn().slideDown();
                }else{
                    $(".form-2-x-y").html("<h4><center><font color='#0183AD' size='17px'>Login success<br><img src='"+base_url+"/themes/default/assets/img/325.gif'></font></center></h4>");
                    setTimeout(window.location.reload(),3000);
                }               
                $(".loading_animate").hide();                
            }
        })
        return false;
    })
})